/*
 * CANGCAL.cpp
 *
 *  Created on: May 1, 2011
 *      Author: ramble
 */

#include "cangcal.h"
#include "math.h"
///////////////////////////////////////////////////////////////////////

static double SinList[360];
static double CosList[360];

void CANGCAL::init() {
	double mypi = 0.017453292519943295769236907684886 ;//3.141592653589793/180;
	double tmp;
	double v;
	for (long i = 0; i < 360; i++) {
		tmp = i;
		v = (tmp * mypi ) ;
		SinList[i] = sin(v);
		CosList[i] = cos(v);
	}
}
;

double CANGCAL::AnSin(double ang) {

	double v1, v2;
	double va = ang;
	while (va < 0.0) {
		va += 360.0;
	}
	while (va > 360.0) {
		va -= 360.0;
	}
	int vt = va;
	if(vt == 360 || vt < 0 )
	{
		return 0.0;
	}
	v1 = SinList[vt];
	v2 = SinList[(vt + 1) % 360];
	double dv = v2 - v1;
	v2 = vt;
	double da = va - v2;
	return v1 + dv * da;
}
double CANGCAL::AnCos(double ang) {//计算COS函数

	double v1, v2;
	double va = ang;
	while (va < 0.0) {
		va += 360.0;
	}
	while (va > 360.0) {
		va -= 360.0;
	}
	int vt = va;
	if(vt == 360 || vt < 0)
	{
		return 1.0;
	}
	v1 = CosList[vt];
	v2 = CosList[(vt + 1) % 360];
	double dv = v2 - v1;
	v2 = vt;
	double da = va - v2;
	return v1 + dv * da;
}

